package com.smartleanx.module.hrm.service.employee.listenser;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.alibaba.fastjson2.JSONObject;
import com.smartleanx.module.bpm.enums.task.BpmProcessInstanceStatusEnum;
import com.smartleanx.module.bpm.event.BpmProcessInstanceStatusEvent;
import com.smartleanx.module.bpm.event.BpmProcessInstanceStatusEventListener;
import com.smartleanx.module.hrm.eums.employee.ProcessDefinitionEnum;
import com.smartleanx.module.hrm.service.employee.EmployeeService;

import lombok.extern.slf4j.Slf4j;

/**
 * 员工离职流程状态监听器
 */
@Slf4j
@Component
public class BpmEmployeeDiligenceListener extends BpmProcessInstanceStatusEventListener {

    @Resource
    private EmployeeService employeeService;

    @Override
    protected String getProcessDefinitionKey() {
        return ProcessDefinitionEnum.DILIGENCE.getKey();
    }

    @Override
    protected void onEvent(BpmProcessInstanceStatusEvent event) {
        if (BpmProcessInstanceStatusEnum.APPROVE.getStatus().equals(event.getStatus())) {
            Map<String, Object> businessData = event.getBusinessData();
            System.out.println(businessData);

            // 员工ID
            String startUser = (String)businessData.get("startUser");
            JSONObject jsonObject = JSONObject.parseObject(startUser);
            Integer userId = jsonObject.getInteger("id");
            // 请假唯一code
            String leaveCode = (String)businessData.get("leaveCode");
            // 请假单位
            String leaveViewUnit = (String)businessData.get("leaveViewUnit");

            JSONObject formData = (JSONObject)businessData.get("formData");

            // 按天
            if ("day".equalsIgnoreCase(leaveViewUnit)) {
                // 开始日期
                String qj_unit_day_start = formData.getString("qj_unit_day_start");
                // 结束日期
                String qj_unit_day_end = formData.getString("qj_unit_day_end");
            }
            // 按半天
            else if ("halfDay".equalsIgnoreCase(leaveViewUnit)) {
                // 开始日期
                String qj_unit_halfDay_start = formData.getString("qj_unit_halfDay_start");
                // 开始时间
                String qj_unit_halfDay_start_option = formData.getString("qj_unit_halfDay_start_option");
                // 结束日期
                String qj_unit_halfDay_end = formData.getString("qj_unit_halfDay_end");
                // 结束时间
                String qj_unit_halfDay_end_option = formData.getString("qj_unit_halfDay_end_option");
            }
            // 按小时
            else if ("hour".equalsIgnoreCase(leaveViewUnit)) {
                // 开始时间
                String qj_unit_hour_start = formData.getString("qj_unit_hour_start");
                // 结束时间
                String qj_unit_hour_end = formData.getString("qj_unit_hour_end");
            } else {
            }

        } else if (BpmProcessInstanceStatusEnum.REJECT.getStatus().equals(event.getStatus())
            || BpmProcessInstanceStatusEnum.CANCEL.getStatus().equals(event.getStatus())) {
        }
    }
}
